#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct Node {
    char name[21];
    struct Node *next;
} node;

node *createnode(char n[]) {
    node *l = (node*)malloc(sizeof(node));
    strcpy(l->name, n);
    l->next = NULL;
    return l;
}

node *insertnode(node *head, char n[]) {
    node *newnode = createnode(n);
    if(head == NULL || strcmp(head->name, n) > 0) {
        newnode->next = head;
        return newnode;
    }
    node *temp = head;
    while(temp->next != NULL && strcmp(temp->next->name, newnode->name) < 0) {
        temp = temp->next;
    }
    newnode->next = temp->next;
    temp->next = newnode;
    return head;
}

node *deletenode(node *head, char d[]) {
    node *l = head;
    node *p = NULL;
    while(l != NULL && strcmp(l->name, d) != 0) {
        p = l;
        l = l->next;
    }
    if(l == NULL) return head;
    if(p == NULL) 
        head = l->next;
    else
        p->next = l->next;
    free(l);
    return head;
}

int querynode(node *head, char q[]) {
    node *l = head;
    while(l != NULL && strcmp(l->name, q) != 0) {
        l = l->next;
    }
    if(l == NULL) return 0;
    return 1;
}

void printlist(node *head) {
    node *l = head;
    while(l != NULL) {
        printf("%s\n", l->name);
        l = l->next;
    }
}

void freelist(node *head) {
    node *l = head;
    node *p;
    while(l != NULL) {
        p = l;
        l = l->next;
        free(p);
    }
}

int main() {
    node *head = NULL;
    char op[10];
    char name[21];
    while (scanf("%s", op) != EOF) {
        if (strcmp(op, "Add") == 0) {
            scanf("%s", name);
            head = insertnode(head, name);
        } else if (strcmp(op, "Delete") == 0) {
            scanf("%s", name);
            head = deletenode(head, name);
        } else if (strcmp(op, "Query") == 0) {
            scanf("%s", name);
            if (querynode(head, name)) {
                printf("Yes\n");
            } else {
                printf("No\n");
            }
        } else if (strcmp(op, "Print") == 0) {
            printlist(head);
        }
    }
    freelist(head);
    return 0;
}//by NANA
